package com.app.teaware.bean;


import android.text.TextUtils;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.ArrayList;
import java.util.List;

public class CompanyListBean extends BaseListBean {

    private ArrayList<CompanyListData> list = new ArrayList<CompanyListData>();

    public ArrayList<CompanyListData> getList() {
        return list;
    }

    public void setList(ArrayList<CompanyListData> list) {
        this.list = list;
    }

    @JSONField(serialize = false)
    public void addListBean(CompanyListBean listbean) {
        if (listbean == null)
            return;
        if (this.getCurrentPage() == INIT_PAGE) {
            setList(listbean.getList());
        } else {
            if (list == null)
                list = new ArrayList<CompanyListData>();
            list.addAll(listbean.getList());
        }
        setListBeanData(listbean);
    }

    public void initCustom(){
        CompanyListData custom = new CompanyListData();
        custom.setCna("客户");
        list.add(0,custom);
    }

    public List<String> getAllCompanyNameList(){
        List<String> nameList = new ArrayList<>();
        if (list.size()>0){
            for (CompanyListData data : list){
                nameList.add(data.getCna());
            }
        }
        return nameList;
    }


    public String[] getAllCustomerNames(){
        List<String> nameList = getAllCustomerNameList();
        if(nameList.size()<1)return null;
        String[] arr = nameList.toArray(new String[nameList.size()]);
        return arr;
    }

    public List<String> getAllCustomerNameList(){
        List<String> nameList = new ArrayList<>();
        if (list.size()>0){
            for (CompanyListData data : list){
                nameList.add(data.getCna());
            }
        }
        return nameList;
    }

    public CompanyListData getCompanyByChoose(int position){
        if (position ==0){
            return  null;
        }else {
           return list.get(position-1);
        }
    }

    public int getPisitionByName(String name){
        if(TextUtils.isEmpty(name)) return 0;
        for (int i =0 ;i<list.size();i++){
            if(list.get(i).getCna().contains(name)){
                return i;
            }
        }
        return 0;
    }

}
